package com.shop2cn.app.liveseller.testcase;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*商品排序
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SortLiveProduct{
	private static SortLiveProductBean sortliveproductBean;
	private static SortLiveProductCall sortliveproductCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品排序");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(
					sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		sortliveproductBean=new SortLiveProductBean();
		sortliveproductCall=new SortLiveProductCall();
		LiveRoomShop2cnWapper=new LiveRoomShop2cnWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sortliveproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SortLiveProduct_001() {
		Logger.start(true,"status0未开始直播商品排序成功");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
//			Logger.verifyEquals(null, sortliveproductCall.getString("code"), "验证Code");
			List<Map> productlist = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(createlive.getId(), null);
			Logger.debug(productlist);
			int i=0;
			for (Map map : productlist) {
				Logger.verifyEquals(ProductIdList.get(i), map.get("ProductId").toString(), "验证商品顺序:"+i);
				i++;
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SortLiveProduct_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			sortliveproductBean.setUserId(createlive.getUserId());
//			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("400", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("参数错误", sortliveproductCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SortLiveProduct_003() {
		Logger.start(true,"不输入ProductIdList失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
//			for (int i = 0; i < count; i++) {
//				String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
//				
//				Logger.comment("创建商品：" + pid);
//				ProductIdList.add(pid);
//			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("400", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("不能为空", sortliveproductCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SortLiveProduct_004() {
		Logger.start(true,"多个商品排序ProductIdList成功");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 10;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
//			Logger.verifyEquals(null, sortliveproductCall.getString("code"), "验证Code");
			List<Map> productlist = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(createlive.getId(), null);
			Logger.debug(productlist);
			int i=0;
			for (Map map : productlist) {
				Logger.verifyEquals(ProductIdList.get(i), map.get("ProductId").toString(), "验证商品顺序:"+i);
				i++;
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_005() {
		Logger.start(true,"status2已经推流直播商品排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_006() {
		Logger.start(true,"status3已经断流直播商品排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 3);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_007() {
		Logger.start(true,"status7系统自动关闭排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_008() {
		Logger.start(true,"status8未推流关闭直播排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_009() {
		Logger.start(true,"status9已推流结束直播排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SortLiveProduct_010() {
		Logger.start(true,"status10运营强制关停排序失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 10);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法修改", sortliveproductCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SortLiveProduct_011() {
		Logger.start(true,"不输入userid失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 3;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
//			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
//			String head="accesstoken="+token;
//			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
			Logger.verifyEquals("400", sortliveproductCall.getString("code"), "验证Code");
//			Logger.verifyEquals("买手Id参数错误", sortliveproductCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SortLiveProduct_012() {
		Logger.start(true,"status1待开始直播商品排序成功");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(createlive.getId());
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
//			Logger.verifyEquals(null, sortliveproductCall.getString("code"), "验证Code");
			List<Map> productlist = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(createlive.getId(), null);
			Logger.debug(productlist);
			int i=0;
			for (Map map : productlist) {
				Logger.verifyEquals(ProductIdList.get(i), map.get("ProductId").toString(), "验证商品顺序:"+i);
				i++;
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SortLiveProduct_013() {
		Logger.start(true,"status1待开始直播商品排序,有商品库存为0,需要正确保存数据");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 5;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(createlive.getId());
			Logger.comment("设置一个商品售罄");
			String soldPid=ProductIdList.get(0);
//			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
//			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(soldPid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
//			ProductManagerCallServiceV2.updateProductStockNum(uinfo.getUserId(), ProductIdList.get(0), catalogs.get(0), 0);
			AgentProductCallService.UpdateStock(sellerId, soldPid, 0);
			Thread.sleep(2000);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+token;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();		
			Logger.verifyEquals("201", sortliveproductCall.getString("code"), "验证Code");
			Logger.verifyIsContains("无法排序", sortliveproductCall.getString("msg"), "验证Msg");
//			Logger.verifyEquals(null, sortliveproductCall.getString("code"), "验证Code");
//			List<Map> productlist = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(createlive.getId(), null);
//			Logger.debug(productlist);
//			int i=0;
//			for (Map map : productlist) {
//				Logger.verifyEquals(ProductIdList.get(i), map.get("ProductId").toString(), "验证商品顺序:"+i);
//				i++;
//			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SortLiveProduct_014() {
		Logger.start(true,"客服直播商品排序成功");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 2;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
						false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			sortliveproductBean.setUserId(createlive.getUserId());
			sortliveproductBean.setLiveId(createlive.getId());
			Collections.shuffle(ProductIdList);
			sortliveproductBean.setProductIdList(ProductIdList);
			sortliveproductCall.setData(sortliveproductBean);
			String head="accesstoken="+cstoken;
			sortliveproductCall.addHeader("ymt-pars", head);
			sortliveproductCall.callService();			
//			Logger.verifyEquals(null, sortliveproductCall.getString("code"), "验证Code");
			List<Map> productlist = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(createlive.getId(), null);
			Logger.debug(productlist);
			int i=0;
			for (Map map : productlist) {
				Logger.verifyEquals(ProductIdList.get(i), map.get("ProductId").toString(), "验证商品顺序:"+i);
				i++;
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}